package com.grass.cropTradingCenter.controller.admin;

import com.grass.cropTradingCenter.common.PageResult;
import com.grass.cropTradingCenter.common.Result;
import com.grass.cropTradingCenter.common.annotation.LoginFree;
import com.grass.cropTradingCenter.pojo.dto.admin.HomeData;
import com.grass.cropTradingCenter.pojo.entity.*;
import com.grass.cropTradingCenter.pojo.vo.admin.AdminUserVo;
import com.grass.cropTradingCenter.pojo.vo.admin.CommitPageVo;
import com.grass.cropTradingCenter.pojo.vo.admin.ShopAuthListVo;
import com.grass.cropTradingCenter.pojo.vo.admin.UpdateAuthStateVo;
import com.grass.cropTradingCenter.pojo.vo.common.PageVo;
import com.grass.cropTradingCenter.pojo.vo.common.UpdateStateVo;
import com.grass.cropTradingCenter.pojo.vo.shop.GoodsListVo;
import com.grass.cropTradingCenter.pojo.vo.user.LoginVo;
import com.grass.cropTradingCenter.service.AdminUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/user")
@Api(tags = "管理员用户接口")
public class AdminUserController {

    @Autowired
    AdminUserService adminUserService;

    @LoginFree
    @PostMapping("/login")
    @ApiOperation("登录")
    public Result<String> login(@RequestBody LoginVo vo){
        return Result.success(adminUserService.login(vo));
    }

    @GetMapping("/userInfo")
    @ApiOperation("获取个人信息")
    public Result<AdminUser> getUserInfo()  {
        return Result.success(adminUserService.getUserInfo());
    }

    @PostMapping("/adminList")
    @ApiOperation("获取管理员列表")
    public PageResult<AdminUser> getAdminList(@RequestBody PageVo vo)  {
        return adminUserService.getAdminList(vo);
    }

    @PostMapping("/addOrUpdateAdmin")
    @ApiOperation("添加或修改管理员信息")
    public Result addOrUpdateAdmin(@RequestBody @Validated AdminUserVo vo)  {
        adminUserService.addOrUpdateAdmin(vo);
        return Result.success();
    }

    @PostMapping("/deleteAdmin")
    @ApiOperation("删除管理员")
    public Result deleteAdmin(@RequestBody AdminUserVo vo)  {
        adminUserService.deleteAdmin(vo);
        return Result.success();
    }

    @PostMapping("/shopAuthList")
    @ApiOperation("获取实名认证列表")
    public PageResult<ShopAuth> shopAuthList(@RequestBody ShopAuthListVo vo)  {
        return adminUserService.shopAuthList(vo);
    }


    @PostMapping("/updateAuthState")
    @ApiOperation("更实名认证审核状态")
    public Result updateAuthState(@RequestBody UpdateAuthStateVo vo)  {
        adminUserService.updateAuthState(vo);
        return Result.success();
    }

    @PostMapping("/updateGoodsCheckFlag")
    @ApiOperation("更农产品审核状态")
    public Result updateGoodsCheckFlag(@RequestBody UpdateStateVo vo) {
        adminUserService.updateGoodsCheckFlag(vo);
        return Result.success();
    }

    @PostMapping("/goodsList")
    @ApiOperation("农产品列表")
    public PageResult<Goods> goodsList(@RequestBody GoodsListVo vo) {
        return adminUserService.goodsList(vo);
    }

    @PostMapping("/commitList")
    @ApiOperation("评论列表")
    public PageResult<UserCommit> commitList(@RequestBody CommitPageVo vo) {
        return adminUserService.commitList(vo);
    }

    @PostMapping("/updateCommitCheckFlag")
    @ApiOperation("更评论审核状态")
    public Result updateCommitCheckFlag(@RequestBody UpdateStateVo vo) {
        adminUserService.updateCommitCheckFlag(vo);
        return Result.success();
    }

    @GetMapping("/shopList")
    @ApiOperation("店铺列表")
    public Result<List<MiniShop>> shopList() {
        return Result.success(adminUserService.shopList());
    }

    @GetMapping("/homeData")
    @ApiOperation("大屏信息")
    public Result<HomeData> homeData() {
        return Result.success(adminUserService.homeData());
    }

}
